package com.yunxi.controller.sys;

import com.github.pagehelper.PageInfo;

import com.yunxi.activiti.pojo.ActivitiManageVO;
import com.yunxi.common.config.RedisCacheService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sys.pojo.AfficheVO;
import com.yunxi.sys.service.AfficheDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by X1165 on 2018/1/22.
 */
@RestController
@RequestMapping("/admin/affiche")
@Api(tags = "cms:affiche", description = "公告管理接口")
public class AfficheController {
    private static final Logger logger = LoggerFactory.getLogger(AfficheController.class);
    @Autowired
    AfficheDubboService afficheDubboService;

    @Resource
    private RedisCacheService rcs;

    /**
     * 公告管理分页
     *
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "公告管理列表")
    public ApiResult page(AfficheVO afficheVO, Integer pageNum, Integer pageSize) throws Exception {
        logger.debug("公告管理列表");
        PageInfo list = afficheDubboService.findPageByVO(afficheVO,pageNum,pageSize);
        return ResponseUtil.ok(list);
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(AfficheVO afficheVO) throws Exception {
        return ResponseUtil.ok(afficheDubboService.listByVo(afficheVO));
    }

    /**
     * 添加/修改公告
     *
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加/修改公告")
    public ApiResult save(@RequestBody AfficheVO afficheVO) throws Exception {
        afficheDubboService.saveOrUpdate(afficheVO);
        return ResponseUtil.ok("success");
    }

    /**
     * 进入公告管理修改页面
     *
     * @return
     */
    @GetMapping("/load")
    @ApiOperation(value = "进入公告管理修改页面")
    public ApiResult load(@RequestParam String id) throws Exception {
        logger.debug("进入公告管理修改页面");
        return ResponseUtil.ok(afficheDubboService.getByAfficheId(id));
    }

    /**
     * 更改发布状态
     *
     * @return
     */
    @PostMapping("/updateStatus")
    @ApiOperation(value = "更改发布状态")
    public Object updateStatus(@RequestBody AfficheVO afficheVO) throws Exception {
        afficheDubboService.saveOrUpdate(afficheVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<AfficheVO> afficheVOList) throws Exception {
        afficheDubboService.removeByListVo(afficheVOList);
        return ResponseUtil.ok("success");
    }
    /**
     * 查询版本最新的的宣告
     * @return
     */
    @GetMapping("/getNewAffiche")
    @ApiOperation(value = "查询版本最新的的宣告")
    public ApiResult getNewAffiche(@RequestParam("afficheType") String afficheType) throws Exception {
        logger.debug("查询版本最新的的宣告");
        return ResponseUtil.ok(afficheDubboService.getNewAffiche(afficheType));
    }

}
